package com.laolei.template.test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.mustache.web.MustacheViewResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;

import com.laolei.template.assist.BuildData;
import com.laolei.template.assist.OutData;
import com.samskivert.mustache.Mustache;

@Component
public class MustacheTemplateBuild implements CommandLineRunner{
	@Autowired MustacheViewResolver mustacheViewResolver;

	@Override
	public void run(String... args) throws Exception {
		this.test();
		this.testResolver();
	}
	
	private void test() throws FileNotFoundException {
		Reader source=new FileReader("src/main/resources/templates/abc.html");
		String result = Mustache.compiler().compile(source).execute(BuildData.build());  
		System.err.println(result);  
	}
	
	private void testResolver() throws Exception {
		 View view= mustacheViewResolver.resolveViewName("abc", Locale.US);
		 OutData.out(view);
	}
}
